<template>
	<el-form ref="form" :model="goods" label-width="80px" @submit.prevent="onSubmit" style="margin:20px;width:60%;min-width:600px;">
		<el-form-item label="商品名">
			<el-input v-model="goods.goodsName"></el-input>
		</el-form-item>
		<el-form-item label="商品价格">
			<el-input type="number" v-model="goods.goodsPrice"></el-input>
		</el-form-item>
		<el-form-item label="商品特色">
			<el-input v-model="goods.goodsCharacteristics"></el-input>
		</el-form-item>
		<!-- <el-form-item label="商品图片">
			<input type="file" @change="selectedFile" name="imageUrl" id="">
		</el-form-item> -->
		<!-- <el-form-item label="所属店铺">
			<el-select @change="selectedShop" v-if="shops!=''" v-model="goods.shopId" placeholder="你要添加到哪个店铺">
			  <el-option  v-for="(item,i) in shops" :key="i" :label="item.shopName" :value="item.shopId" >
				  {{item.shopName}}
			  </el-option>
			</el-select>
		  </el-form-item> -->
		  <el-form-item label="所属分类">
			 <el-select v-if="selectedClassify!=1" v-model="goods.classifyId" placeholder="你要添加到哪个分类">
			  <el-option v-for="(item,i) in selectedClassify" :key="i" :label="item.classifyName" :value="item.classifyId">
				  {{item.classifyName}}
			  </el-option>
			</el-select>
		  </el-form-item>
		<el-form-item>
			<el-button @click.stop="regGoods" type="primary">提交</el-button>
			<el-button @click.native.prevent>取消</el-button>
		</el-form-item>
	</el-form>
	
</template>

<script>
	export default {
		created(){
this.getShops()
		},
		data() {
			return {
				fileList: [],
				file: '',
				goods: {
					shopId:'',
					goodsCharacteristics:'',
					goodsName: '',
					goodsPrice:'',
					merchantId:this.$store.state.user.merchantId,
					classifyId:''
				},
				shops:'',
				selectedClassify:'',
			}
		},
		methods: {
			selectedFile(e){
				this.file = e.target.files[0]
				let config = {
                    headers:{'Content-Type':'multipart/form-data'}
                };
				this.$axios({
					method:'post',
					url:'/addGoods',
					data:{
						imageUrl:e.target.files[0]
					},config
				}).then(r=>{
				})
			},
			selectedShop(data){
				this.goods.shopId = data
				this.$axios({
					method:'get',
					params:{
						shopId:data
					},
					url:'/getClassify'
				}).then(r=>{
					if(r.data.err_code==0){
						this.selectedClassify = r.data.result
					}else{
						this.selectedClassify=1
					}
				})
			},
			handleUpSuc(res){
			},
			submitUpload() {
				this.$refs.upload.submit();
			},
			handlePreview(file) {
			},
			getShops(){
				this.$axios({
					method:'get',
					params:{
						merchantId:this.$store.state.user.merchantId
					},
					url:'/getShop'
				}).then(r=>{
					this.shops = r.data.result
				}).catch(err=>{
					this.$error()
				})
			},
			regGoods(){
				let data = this.goods
				this.$axios({
					method:'post',
					url:'/addGoods',
					data
				}).then(r=>{
				})
			},
			onSubmit() {
			}
		}
	}

</script>

<style scoped>
	.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>